package com.itgaoshu.hospitalproject.mapper;

import com.itgaoshu.hospitalproject.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ChufangMapper {

    List<CWarehuose> selware();

    List<CPharmacy> selectAllCPh(CPharmacy cPharmacy);

    @Select("select r.reportId,r.reportName,DATE_FORMAT(r.time,'%Y-%m-%d') datime,r.carid,r.phone,r.sex,r.age,p.department,d.doctorName,r.price,e.type,r.time,r.users,r.state,e.registeredid dregisteredid,d.doctorid ddoctorid,p.departmentId ddepartmentid from report r,registeredtype e,doctor d,departments p where state=1 and r.reportType=e.registeredId and r.doctor=d.doctorId and r.department=p.departmentId")
    List<ReportVo> selectCf();

    @Select("select * from cashier where reportId=#{perid} and state !=2")
    List<CCashier> selectAllCC(int perid);

    @Select("select * from cashier where reportId=#{perid} and state =0")
    List<CCashier> selpepi(int perid);

    @Select("select zhuan from report where reportid=#{reid}")
    Object selectBing(Integer reid);

    @Update("UPDATE report SET zhuan = #{zhuan} WHERE reportId = #{reportId}")
    int addbing(CReport cReport);

    @Select("SELECT * FROM cashier WHERE reportId=#{reportId} AND durgname=#{durgname}")
    Integer selcadr(CCashier cCashier);

    @Update("INSERT INTO cashier (reportId,durgname,durgnum,repiceprice,repicetotal,state,ctime) VALUES (#{reportId},#{durgname},#{durgnum},#{repiceprice},#{repicetotal},0,NOW())")
    Integer addchu(CCashier cCashier);

    @Update("UPDATE pharmacy SET drugstorenum = drugstorenum-#{drugstorenum} WHERE pharmacyName = #{pharmacyName}")
    Integer deldrunum(CPharmacy cPharmacy);

    @Update("UPDATE cashier SET durgnum = durgnum+#{durgnum},repicetotal=repicetotal+#{repicetotal} WHERE durgname = #{durgname}")
    Integer updchu(CCashier cCashier);

    //查看该用户有几个已经做过的项目
    Integer selyi(Integer reid);
    //查询该用户有几个已经交过钱的项目
    Integer selgong(Integer reid);

    //查询用户项目的处方
    @Select("select * from cashier where reportId=#{perid} and state =1")
    List<CCashier> selximu(Integer perid);

    //删除处方中的药品
    @Update("DELETE FROM cashier WHERE cashier = #{cashier}")
    Integer del(CCashier cCashier);

    //添加药品数量
    @Update("UPDATE pharmacy SET drugstorenum = drugstorenum+#{drugstorenum} WHERE pharmacyName = #{pharmacyName}")
    Integer adddrunum(CPharmacy cPharmacy);

}
